﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;


namespace EP2_LoginServer
{
    public static class mySQL
    {
        public static string host, database, user, password;

       
       

        public static void Test()
        {
            string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
            MySqlConnection mysqlCon = new MySqlConnection(strProvider);
            try
            {
                mysqlCon.Open();
                LogScreen.Info("mySQL Connected");
                
            }
            catch
            {
                LogScreen.Error("mySQL Error");
            }
        }

        public static bool VerifyLogin(string UserName, string Password)
        {
            string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
            MySqlConnection mysqlCon = new MySqlConnection(strProvider);
            mysqlCon.Open();

            MySqlCommand verifyUser = new MySqlCommand("SELECT a_index, a_lastserver, a_lastchannel FROM t_users WHERE a_username=\"" + UserName + "\" AND a_password = \"" + Password + "\";", mysqlCon);
            verifyUser.ExecuteNonQuery();

            MySqlDataReader myReader = verifyUser.ExecuteReader();
            if (myReader.Read() == false) return false;
            else return true;

        }
    }
}
